// 引入第三方模块
const express = require('express');
// 引入连接池模块
const pool = require('../pool.js');
// 创建路由器对象
const r = express.Router();

// 搜索数据单条查询
r.get('/', (req, res, next) => {
    var obj = req.query.seid;
    console.log(obj);
    // 执行SQL命令
    pool.query("select * from search where sid = ?", [obj], (err, result) => {
        if (err) {
            next(err);
            return;
        }
        console.log(result);
        if (result.length === 0) {
            res.send({
                code: 500,
                msg: "查询失败"
            });
        } else {
            res.send({
                code: 200,
                msg: "查询成功",
                data: result
            });
        }
    })
})
// 搜索数据所有查询
r.get('/AllData', (req, res, next) => {
    // 执行SQL命令
    pool.query("select * from search", (err, result) => {
        if (err) {
            next(err);
            return;
        }
        console.log(result);
        if (result.length === 0) {
            res.send({
                code: 500,
                msg: "查询失败"
            });
        } else {
            res.send({
                code: 200,
                msg: "查询成功",
                data: result
            });
        }
    })
})

// 导出路由器对象
module.exports = r;